package com.hldsmart.smartda.utils;

import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.telephony.TelephonyManager;

import static android.content.Context.TELEPHONY_SERVICE;

/**
 * Created by liuzhihui on 2017/1/19.
 */

public class getMacAddress {

    //唯一标识的长度
    private static int IDENTIFY_LEN=12;

    //根据Wifi信息获取本地Mac
    public static String getLocalMacAddressFromWifiInfo(Context context){
        WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        WifiInfo info = wifi.getConnectionInfo();
        return info.getMacAddress();

    }

    public static void getAndroidInfo(Context context) {
        TelephonyManager mTm = (TelephonyManager)context.getSystemService(TELEPHONY_SERVICE);
        String imei = mTm.getDeviceId();
        String imsi = mTm.getSubscriberId();
        String mtype = android.os.Build.MODEL; // 手机型号
        String numer = mTm.getLine1Number(); // 手机号码，有的可得，有的不可得
    }



    //格式化唯一标识
    private static String formatIdentify(String identify)
    {

        //判空
        if(identify.isEmpty())
        {
            return identify;
        }
        //去除空格
        identify = identify.trim();
        //求长度
        int len = identify.length();
        //正好
        if(len== IDENTIFY_LEN)
        {
            return identify;
        }
        //过长，截取
        if(len>IDENTIFY_LEN)
        {
            return identify.substring(0, IDENTIFY_LEN);
        }
        //过短，补0
        for(;len<IDENTIFY_LEN;len++)
        {
            identify += "0";
        }
        //大于默认
        return identify;
    }


}
